/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package controller.web;

/**
 *
 * @author Hatta
 */
import business.OrderList;
import business.Order;
import business.User;
import business.Admin;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.http.HttpSession;
import org.eclipse.persistence.sessions.Session;

public class OrderListServlet extends Servlet {
    private User user;

    public OrderListServlet() {
        super();
        setTemplate("/WEB-INF/OrderList.jsp");
    }

    @Override
    protected void process() {
      setMessage("");
        OrderList dib = new OrderList();
        HttpSession session = getRequest().getSession();
        String mem = (String) session.getAttribute("username");
        if(validate_book()){
            List<Order> i = (List<Order>) dib.getBOp(mem);
            getRequest().setAttribute("orderList", i.iterator());
        }
        else{
            try {
                getResponse().sendRedirect("OrderListKosong");
            } catch (IOException ex) {
                Logger.getLogger(OrderListServlet.class.getName()).log(Level.SEVERE, null, ex);
            }

            }
        }

    private boolean validate_book(){
        OrderList dib = new OrderList();
        HttpSession session = getRequest().getSession();
        String mem = (String) session.getAttribute("username");
        int xx = dib.getJumlahOrderAd(mem);

        if( xx == 0){
            return false;
        }

        return true;
    }
}
